package br.com.escolaespacocrianca.fineec.model;

import java.util.GregorianCalendar;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToOne;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class BaseEntity {
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	protected Integer id;
	private boolean deleted;
	
	private GregorianCalendar createDate;
	private GregorianCalendar updateDate;
	
	@OneToOne
	@Cascade(value={CascadeType.REFRESH})
	private User createUser;
	
	@OneToOne
	@Cascade(value={CascadeType.REFRESH})
	private User updateUser;	
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void delete(){
		this.setDeleted(true);
	}
	
	@Override
	public boolean equals(Object obj) {
		
		if (obj instanceof BaseEntity){
			BaseEntity entity = (BaseEntity)obj;
			
			if (this.getId() != null && entity.getId() != null){
				if( this.getId().equals(entity.getId())){
					return true;
				}
			}
		}
		
		return false;
	}

	public GregorianCalendar getCreateDate() {
		return createDate;
	}

	public void setCreateDate(GregorianCalendar createDate) {
		this.createDate = createDate;
	}

	public GregorianCalendar getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(GregorianCalendar updateDate) {
		this.updateDate = updateDate;
	}

	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	public User getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(User updateUser) {
		this.updateUser = updateUser;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

		
}
